
<script>
function Del_Info(str){
	var q=confirm('Bạn có chắc chắn muốn xóa hay không?');	
	if(q==true) 
		window.location=str;
	
}
</script>
<?php
$sql="SELECT substr( QUYEN,6, 1 ) as mq
FROM qldl_tai_khoan
WHERE ten_dang_nhap = '".$_SESSION['username']."'";
	$query = @mysql_query($sql,$conn);
	$row = @mysql_fetch_array($query);
	if($row['mq']==1){
	 header('Location: index.php?page=id_edit_gt&amp;id_edit_gt="'.$_GET['id_edit_gt'].'"'); 
	}
	else {
	echo  "<script>alert ('Bạn không có quyền truy cập trang này!')</script>"; 
	echo "<meta http-equiv='refresh' content='0;url= index.php'>";
	}
?>
<div class="cpanel-right-tttk">
  <div id="panel-sliders" class="pane-sliders">
    <div class="panel">
      <table width="100%" border="0" cellspacing="0" cellpadding="0" style=" padding:10px;">
        <thead>
        <tr style=" padding-bottom:10px;">
        <th colspan="3" align="left" style="padding-bottom:10px;">QUẢN LÍ BÀI GIỚI THIỆU</th> 
        </tr> 
        <?php  
if(isset($_POST['btn_edit_gt'])){ 
	$mgt=$_GET['id_edit_gt'];
	$td=$_POST['txt_td_gt'];
	$ct=$_POST['area'];
	$ngd=$_POST['txt_ngd'];
	///////	
	
	/////////////////
	
	if ($_FILES["file_up"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file_up"]["error"] . "<br />";
    }
  else
    { $link =$_FILES["file_up"]["name"];
    if (file_exists("dia_diem/upload/news/" . $_FILES["file_up"]["name"]))
      {
      	echo $_FILES["file_up"]["name"] . " da ton tai file tren server. ";
      }
    else
      {  
      move_uploaded_file($_FILES["file_up"]["tmp_name"],
      "dia_diem/upload/news/" . $_FILES["file_up"]["name"]);	 
      }
		$sql2="select * from qldl_gioi_thieu where STT='".$_GET['id_edit_gt']."'";
		$query2 = @mysql_query($sql2,$conn);
		 $row2 = @mysql_fetch_array($query2);
			/////
		if($link=''){
			$link=$row2['HINH_ANH'];
			}
	}
	/////
	
	 $sql1 = "update qldl_gioi_thieu set				
				TIEU_DE='$td',
				CHI_TIET='$ct',
				HINH_ANH='$link',
				NGAY_DANG='$ngd'
			where STT='$mgt'
			";
	$query1 = @mysql_query($sql1,$conn);
	/////////////////////////////
	if($query1)echo "<script>alert ('Cập nhật thông tin thành công.')</script>";	
	else echo "<script>alert ('Lỗi cập nhật thông tin!')</script>";	
	echo  "<meta http-equiv='refresh' content='0;url=index.php?page=g_thieu'>";
}
?>
        </thead>
        
        <tr valign="top" style="padding:5px;">
          <td width="53%"><div style=" padding:0px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left">
            <form action="" method="post" name="form_edit" id="form_edit" onsubmit="return input_edit();">
            <table width="100%" border="1" bordercolor="#666666" class="adminlist_tt">
              
              <thead>
                <tr>
                  <th colspan="2"> Sửa bài giới thiệu</th>
                </tr>
               
              </thead>
              <tbody>
              
              
<?php  
	$sql="select * from qldl_gioi_thieu where STT='".$_GET['id_edit_gt']."'";
	$query = @mysql_query($sql,$conn);	
	if(!$query) echo "Query error to display.";
	else $row = @mysql_fetch_array($query);
		
  ?>  
                <tr>
                  <td>Tiêu đề</td>
                  <td><input type="text" name="txt_td_gt" id="txt_td_gt" value="<?php echo $row['TIEU_DE'];?>" width="180px" /></td>
                  </tr>
                <tr>
                  <td>Chi tiết</td>
                  <td><label for="area"></label>
                    <textarea name="area" id="area" style="height:100px; width:100%;"><?php echo $row['CHI_TIET'];?></textarea></td>
                  </tr>
                <tr>
                  <td>File ảnh</td>
                  <td><input type="file" name="file_up" /><?php echo $row['HINH_ANH'];?></td>
                  </tr>
                <tr>
                  <td>Ngày đăng</td>
                  <td><label for="textfield"></label>
                  <input type="text" name="txt_ngd" id="txt_ngd" value="<?php echo date('Y-m-d')?>" /></td>
                </tr>
                <tr>
                  <td colspan="2"><input type="submit" name="btn_edit_gt" id="btn_edit_gt" value="Lưu" />
                    <input type="reset" name="btn_huy_gt" id="btn_huy_gt" value="Hủy"/>
      
                    </td>
                </tr>
              </tbody>
            </table>
            </form>
          </div></td>
          <td width="1%" align="center">&nbsp;</td>
          <td width="46%"><div style=" padding:0px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left">
            <table width="100%" border="1" bordercolor="#666666" class="adminlist_tt">
              <thead>
                <tr>
                  <th colspan="4"> Danh sách bài giới thiệu</th>
                  <?php include('gioi_thieu/del.php'); ?>
                </tr>
              </thead>
              <tbody>
              
                <tr>
                  <td width="51">Stt</td>
                  
                  <td width="227">Tiêu đề</td>
                  <td width="130">Cập nhật</td>
                </tr>
                <?php
				$stt=0;
	$sql="select * from qldl_gioi_thieu";
	$query = @mysql_query($sql,$conn);	
	if(!$query) echo "Query error to display.";
	else while($row = @mysql_fetch_array($query)){
		$stt++;
			?>	
                <tr>
                  <td><?php echo $stt;?></td>
                  
                  <td><?php echo $row['TIEU_DE'];?></td>
                  <td><a href="index.php?page=id_edit_gt&amp;id_edit_gt=<?php echo $row['STT'];?>">Sửa</a> || 
                  <a onclick="Del_Info('index.php?page=g_thieu&amp;id_del_gt=<?php echo $row['STT'];?>&amp;id_photo_gt=<?php echo $row['HINH_ANH']; ?>');" href="#">Xóa</a></td>
                </tr>
                <?php
					}
				?>
              </tbody>
            </table>
          </div></td>
        </tr>
      </table>
    </div>
  </div>
</div>
